﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

namespace EasySchedule.Controls
{
    public class ExtendedListView : ListView
    {
        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.Register("Command", typeof(ICommand), typeof(ExtendedListView), new PropertyMetadata(null));

        protected override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            this.ItemClick += OnItemClick;
            
        }

        void OnItemClick(object sender, ItemClickEventArgs e)
        {
            if (this.Command == null) return;
            if (this.Command.CanExecute(e.ClickedItem))
                this.Command.Execute(e.ClickedItem);
        }  
    }
}
